package com.syygl.chase.core;


import com.syygl.chase.annotation.NeedLoadedDataTag;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Aspect
@Service
public class NeedLoadedDataAspect {
    @Autowired
    IProcessDataMethod iProcessDataMethod;

    @PostConstruct
    public void setcommonPoolSize(){
        System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "10");
    }

    @Pointcut("@annotation(com.syygl.chase.annotation.NeedLoadedDataTag)")
    public void needLoadedDataAspectPointCut() {
    }

    @Around(value = "needLoadedDataAspectPointCut()")
    public Object aroundNeedLoadedDataMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        Object obj = null;
        try {
            //获取方法上的注解
            NeedLoadedDataTag needLoadedDataTag = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(NeedLoadedDataTag.class);
            //被注解标注方法上的入参
            Object[] args = joinPoint.getArgs();
            iProcessDataMethod.processSerialData(needLoadedDataTag.serialPrepareData(), args);
            iProcessDataMethod.processParallelData(needLoadedDataTag.parallelPrepareData(), args);
            obj = joinPoint.proceed();
        } catch (Exception e) {

        } finally {

        }
        return obj;
    }




}
